package com.hzqy.web.ac.epg;


import com.hzqy.commons.utils.ExcelUtil;
import com.hzqy.commons.utils.ExcelUtil.MyEntry;
import com.hzqy.service.epg.AcConfigService;
import com.hzqy.web.vo.AcWinningVo;
import com.hzqy.web.vo.epg.AcConfigVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/acConfig")
public class AcConfigAction {
    @Resource
	private AcConfigService serviceAction;
    @RequestMapping("/acConfigSelectAll")
	@ResponseBody
	public Object acConfigSelect(AcConfigVo acv, int page, int rows){
		Map<String,Object> ConfigListMap = new HashMap<String, Object>();
		ConfigListMap= serviceAction.selectAc(acv,page, rows);
		return ConfigListMap;
	}
	@RequestMapping("/acConfigExcel")
	@ResponseBody
	public void acConfigExcel(AcConfigVo infoVo, HttpSession session, int page, int rows, HttpServletResponse response) throws IOException {
		Map<String,Object> ListMap = new HashMap<String, Object>();
    	ListMap = serviceAction.selectAc(infoVo,1,100000);
		List<AcConfigVo> data=(List<AcConfigVo>)ListMap.get("rows");
		List<MyEntry<String, String>> excelHeader=new ArrayList<MyEntry<String, String>>();
		excelHeader.add(new MyEntry<String,String>("f_ac_id","ID"));
		excelHeader.add(new MyEntry<String,String>("f_ac_name","活动名称"));
		excelHeader.add(new MyEntry<String,String>("f_ac_activityid","活动编号"));
		excelHeader.add(new MyEntry<String,String>("f_ac_periods","竞赛期数"));
		excelHeader.add(new MyEntry<String,String>("f_ac_code","选手编号"));
		excelHeader.add(new MyEntry<String,String>("f_ac_udate","签到时间"));
		excelHeader.add(new MyEntry<String,String>("f_ac_cdate","创建时间"));
		boolean flag= ExcelUtil.generateExcel(data, excelHeader, response);
	}
	@RequestMapping("/acConfigInsert")
	@ResponseBody
	public Map acConfigInsert(AcConfigVo infovo,HttpSession session){
    	Map<String,Object> map=new HashMap<String,Object>();
		Integer num = serviceAction.ConfigDataInsert(infovo);
        if(num==1){
			map.put("success", true);
			map.put("result","新增内容成功!");
		}else{
			map.put("success", false);
			map.put("result","新增内容失敗!");
		}
        return map;
	}

}
